#!/usr/bin/make -f

export DH_VERBOSE=1
export THIRDPARTY=build/3rdparty
export THIRDPARTY_SRC=${THIRDPARTY}/src
export THIRDPARTY_INC=${THIRDPARTY}/include
export THIRDPARTY_LIB=${THIRDPARTY}/lib

export GRDIR=/usr/gr
export DEB_BUILD_ROOT=/usr/src/packages/BUILD/debian
#export DEB_BUILD_ROOT=/home/felder/dpkg/gr/debian

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
ifeq ( $(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/qt5/bin/qmake), )
	QT5_QMAKE=qmake-qt5
else
	QT5_QMAKE=/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/bin/qmake
endif

%:
	dh $@

override_dh_auto_configure:
	mkdir -p ${THIRDPARTY_SRC}
	cp ../SOURCES/libogg-1.3.2.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/libtheora-1.1.1.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/libvpx-1.4.0.tar.bz2 ${THIRDPARTY_SRC}
	cp ../SOURCES/ffmpeg-4.2.1.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/glfw-3.3.3.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/zeromq-4.3.4.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/cairo-1.16.0.tar.xz ${THIRDPARTY_SRC}
	cp ../SOURCES/pixman-0.40.0.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/tiff-4.0.10.tar.gz ${THIRDPARTY_SRC}
	cp ../SOURCES/libopenh264-2.0.0.tar.gz ${THIRDPARTY_SRC}

override_dh_auto_build:
	make -C 3rdparty GRDIR=${GRDIR} DIR=`pwd`/${THIRDPARTY}
	make -C 3rdparty extras GRDIR=${GRDIR} DIR=`pwd`/${THIRDPARTY}
	make GRDIR=${GRDIR} \
		EXTRA_CFLAGS=-I`pwd`/${THIRDPARTY_INC} \
		EXTRA_CXXFLAGS=-I`pwd`/${THIRDPARTY_INC} \
		EXTRA_LDFLAGS=-L`pwd`/${THIRDPARTY_LIB} \
		THIRDPARTYDIR=`pwd`/${THIRDPARTY} \
		QT5_QMAKE=${QT5_QMAKE}

override_dh_auto_install:
	mkdir -p ${DEB_BUILD_ROOT}/gr${GRDIR}
	make install GRDIR=${GRDIR} THIRDPARTYDIR=`pwd`/${THIRDPARTY} DESTDIR=${DEB_BUILD_ROOT}/gr
